<%@page import="Entity.Event"%>
<%@page import="Entity.User"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>考试/竞赛</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<link href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
	<script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
	<script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
	<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" integrity="sha512-SfTiTlX6kk+qitfevl/7LibUOeJWlt9rbyDn92a1DqWOw9vWG2MFoays0sgObmWazO5BQPiFucnnEAjpAB+/Sw==" crossorigin="anonymous" referrerpolicy="no-referrer" />
	<link rel="shortcut icon" type="image/x-icon" href="logo.jpg" />

	<style type="text/css">
	button{
	width: 80px;
	height: 40px;
	margin-left:40px;
	margin-top:20px;
	text-align: center;
	border-radius: 10px;
	background: linear-gradient(145deg, #6a71d3, #7e87fa);
	
	}
body {
	background-image: linear-gradient(to top, #e6e9f0 0%, #eef1f5 100%);
}
	</style>
  </head>
  
  <body>
  <%
   User user =(User) session.getAttribute("user");
  	 if(user==null){
  	 	 request.getRequestDispatcher("login.jsp").forward(request,response);
  	 } 
  	 List<Event> events =(List<Event>)request.getAttribute("event");
  	 Integer totalPage=(Integer)request.getAttribute("sum");
  	  Integer cpage=(Integer)request.getAttribute("cpage");
  	 %>
  <!-- 顶部-->
    	<div style="border: 1px;display: block;">
    			<image  src="image/title.png" style="width: 600px;">
    			<a href="personInfor.jsp" class="btn dropdown-toggle"  style="float: right;margin:auto 40px;">
    			<i class="fa fa-user-circle fa-2x"></i>
    			个人信息
		   		 </a>
    	</div>
    		<div style="float: left;width: 10%;height:90%; bottom:0;display: block;border-radius: 10px;
   		background-image: linear-gradient(to top, #accbee 0%, #e7f0fd 100%);">
    			<ul class="nav nav-pills nav-stacked">
			  <li><a href="RoomServlet"><img src="image/m_1.png" width="25px" style="margin-right: 5px;">机房信息</a></li>
			  <li><a href="SearchServlet?cpage=1">用户信息</a></li>
				  <li>
					<a type="button" class="btn " data-toggle="collapse" 
					    data-target="#demo" >
					     实验安排
					</a>    
					<div id="demo" class="collapse"  style="text-align: center;
						background-image: linear-gradient(to top, #accbee 0%, #e7f0fd 100%);">
					  <a class="btn " href="class_total.jsp" style="color: white;">课程日历</a>
					 <a class="btn " href="searchCourseServlet?page=1" style="color: white;">查看课程</a>
					</div>
				  <li class="active"><a href="EventServlet?page=1">考试/竞赛</a></li>
				  <li><a href="sendmessage.jsp">发件箱</a></li>
			</ul>
    		</div>
		     <button  data-toggle="modal" data-target="#myModal" width="40px">增加</button>
    	
	    	<form action="" method="post">
		     
		    
		    <div class="table-responsive" style="width:85%;margin-left: 10px;" >
		    
		    <table  class="table table-striped" style="max-height: 300px;width: 900px; margin:0 auto;" >
		    <thead>
			    <tr>
			     <th>考试编号</th>
	             <th>性质</th>
	             <th>时间</th>
	             <th>机房</th>
	             <th>操作</th>
			    </tr>
		    </thead>
		    <tbody>
				 <%
				for(Event event:events){
				%>
				<tr>
				<td><%=event.getEid() %></td>
				<td><%if(event.getType()==1){%>竞赛<%}else{%>考试<%} %></td>
				<td><%=event.getDate()%><%="第"%><%=event.getOrder() %><%="大节"%></td>
				<td><%=event.getRoom() %></td>
				<td><a href="DeleteEventServlet?eid=<%=event.getEid() %>&page=<%=cpage%>">删除</a></td>
				</tr>
				<%
				}
				 %>   
			  </tbody>    
		    </table>
		    </div>
		    <div style="text-align: center;margin: 20px auto;">
		    <%
					if(cpage==1){
						if(cpage!=totalPage){
					
					%>
							共<%=cpage %>/<%=totalPage %>页
							<a href="EventServlet?page=<%=cpage+1 %>">下一页</a>
							<a href="EventServlet?page=<%=totalPage %>">尾页</a>
					<%
						}else if(cpage==totalPage){
						%>
							共1/1页
						<%
						}
					}else if(cpage==totalPage){
						%>
							共<%=cpage %>/<%=totalPage %>页
							<a href="EventServlet?page=1">首页</a>
							<a href="EventServlet?page=<%=cpage-1 %>">上一页</a>
						<%
					}else{
						%>
							<a href="EventServlet?page=1">首页</a>
							<a href="EventServlet?page=<%=cpage-1 %>">上一页</a>
							共<%=cpage %>/<%=totalPage %>页
							<a href="EventServlet?page=<%=cpage+1 %>">下一页</a>
							<a href="EventServlet?page=<%=totalPage %>">尾页</a>
						<%
					}
					
				 %>
				</div>
	    	</form>
	    	<!-- 模态框（Modal） -->
		<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
		    <div class="modal-dialog">
		        <div class="modal-content">
		            <div class="modal-header">
		                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
		                <h4 class="modal-title" id="myModalLabel">添加考试/竞赛</h4>
		            </div>
		            <div class="modal-body">
						<form class="form-horizontal" role="form"  name="form"  method="post" action="eventQueryServlet">
				  <div class="form-group">
				    <label for="lastname" class="col-sm-2 control-label">考试/竞赛名称</label>
				    <div class="col-sm-10">
				      <input type="text" class="form-control" name="text_name" placeholder="请输入.." style="width: 300px;">
				    </div>
				  </div>
				   <div class="form-group">
				    <label for="name" class="col-sm-2 control-label">类型</label>
				    <select   name="typeT">
					      <option width="40px" value="1">竞赛</option>
				      	<option width="40px" value="2">考试</option>
					    </select>
					</div>
				   <div class="form-group">
				    <label for="lastname" class="col-sm-2 control-label">日期</label>
				    <div class="col-sm-10">
				      <input type="date" id="date" name="date" onchange="upperCase();">
				    </div>
				  </div>
				  <div class="form-group">
				    <label for="name" class="col-sm-2 control-label">时间</label>
				    <select   name="order">
					    <option width="40px" value="1">第一大节</option>
				      	<option width="40px" value="2">第二大节</option>
				      	<option width="40px" value="3">第三大节</option>
				      	<option width="40px" value="4">第四大节</option>
				      	<option width="40px" value="5">第五大节</option>
					    </select>
					</div>
					</div>
				  <div class="form-group">
				    <label for="name" class="col-sm-2 control-label">机房</label>
				    <select   name="room">
					    <option width="40px" value="1001">1001</option>
				      	<option width="40px" value="1002">1002</option>
				      	<option width="40px" value="1003">1003</option>
				      	<option width="40px" value="1004">1004</option>
				      	<option width="40px" value="1005">1005</option>
					    </select>
					</div>
			
					</div>
		            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="submit" class="btn btn-primary">提交更改</button>
                </form>
            </div>
		        </div><!-- /.modal-content -->
		    </div><!-- /.modal -->
		</div>
  	
    <script type="text/javascript">
            var now = new Date();
        //格式化日，如果小于9，前面补0
        var day = ("0" + now.getDate()).slice(-2);
        //格式化月，如果小于9，前面补0
        var month = ("0" + (now.getMonth() + 1)).slice(-2);
        //拼装完整日期格式
        var today = now.getFullYear()+"-"+(month)+"-"+(day) ;
        document.getElementById("date").value=(today);
        //or  $("#date").val(today);
        </script>
       <script type="text/javascript">
		function upperCase()
		{
			document.getElementById("dateForm").submit();
		}
		</script> 
  </body>
</html>
